import React, { Component } from 'react';
import { wxShare } from '../../utils/weixinShare';
import {
    Flex,
    Icon,
    Modal,
    Carousel,
    WingBlank,
    WhiteSpace,
    Toast,
    SwipeAction,
    Popover
} from 'antd-mobile';

import Moment from 'moment';
import NoLazyImg from '../../components/NoLazyImg/NoLazyImg';

import fenxiaoShare from '../../assets/svg/fenxiaoShare.svg';
import {evalute_madel} from "../evaluate/EvaluateListItem.less";

import { routerRedux } from 'dva/router';
import {IMAGE_DOMAIN, isWechat} from "../../utils/common";




class DistributionItem extends Component {
    constructor(props){
        super(props);
        this.state={

        };

    }

    jiaru=()=>{
        const { v, dispatch } = this.props;
        dispatch({ type: 'distribution/joinStoreEFF', obj:{goodsId :v.goodsId ,distributorId :v.distributorId } }).then(result=>{
            if(result.code==200){
                Toast.success(result.msg,2,()=>{
                    this.props.refresh();
                })
            }else if(result.code==403){
                Toast.info(result.msg,2);
            }
        });
    }
    render () {
        const { v, dispatch ,my} = this.props;
        return (
            <div    style={{background:"#fff",padding:".2rem 0"}} >
                {my? <SwipeAction  style={{backgroundColor: 'gray', width: "100%"}} autoClose
                                   right={[
                                       {
                                           text: '删除商品',
                                           onPress: () => {
                                               dispatch({ type: 'distribution/delGoodsEFF', obj:{goodsId :v.goodsId  } }).then(result=>{
                                                   if(result.code==200){
                                                       Toast.success(result.msg,2,()=>{
                                                           this.props.refresh();
                                                       })
                                                   }
                                               });
                                           },
                                           style: {backgroundColor: '#ff0036', color: 'white'},
                                       },
                                   ]} >
                    <div style={{ paddingLeft:'0.14rem' }}>

                        <Flex className="goods_list_item" style={{borderTop:"1px solid #fff"}}>
                            <div className="goods_img" onClick={()=>{ dispatch(routerRedux.push(`/goodsDetail/${v.dspecId}`));return false; }}>
                                <NoLazyImg src={ v.goodsImage?v.goodsImage :""  } />
                            </div>
                            <Flex className="goods_content" justify="between" >
                                <Flex direction="column" style={{width:"70%"}} onClick={()=>{ dispatch(routerRedux.push(`/goodsDetail/${v.dspecId}`));return false; }}>
                                    <div className="name text-two-eli"  >{ v.goodsName  }</div>
                                    <Flex style={{width:"100%"}}>
                                        {v.storeId==0?<div style={{border:"1px solid #F17878",color:"#F17878",padding:".05rem",borderRadius:".1rem",marginRight:".2rem"}}>自营</div>:""}
                                        <div className="price" >￥{ v.goodsPrice }</div>
                                    </Flex>
                                    <div className="commentnum_evaluate">
                                        <span>月销：{ v.salenum  }件</span>
                                        <span style={{ marginRight:"0.5rem" }}>评价数：{v.evaluateCount }</span>
                                    </div>
                                </Flex>
                                <div style={{textAlign:"center"}}>
                                    <div className="jiaruxiaodian" onClick={(e)=>{
                                        dispatch(routerRedux.push(`/goodsDetail/${v.dspecId}`))
                                    }
                                    }>立即购买</div>
                                </div>
                            </Flex>

                        </Flex>
                    </div>
                </SwipeAction>: <div style={{ paddingLeft:'0.14rem' }}>

                    <Flex className="goods_list_item">
                        <div className="goods_img" onClick={()=>{ dispatch(routerRedux.push(`/goodsDetail/${v.dspecId}`));return false; }}>
                            <NoLazyImg src={ v.goodsImage?v.goodsImage :""  } />
                        </div>
                        <Flex className="goods_content" justify="between" >
                            <Flex direction="column" style={{width:"70%"}} onClick={()=>{ dispatch(routerRedux.push(`/goodsDetail/${v.dspecId}`));return false; }}>
                                <div className="name text-two-eli"  >{ v.goodsName  }</div>
                                <Flex style={{width:"100%"}}>
                                    {v.storeId==0?<div style={{border:"1px solid #F17878",color:"#F17878",padding:".05rem",borderRadius:".1rem",marginRight:".2rem"}}>自营</div>:""}
                                    <div className="price" >￥{ v.goodsPrice }</div>
                                </Flex>
                                <div className="commentnum_evaluate">
                                    <span>月销：{ v.salenum  }件</span>
                                    <span style={{ marginRight:"0.5rem" }}>评价数：{v.evaluateCount }</span>
                                </div>
                            </Flex>
                            {this.props.myStore?  <div style={{textAlign:"center"}}>
                                <div className="jiaruxiaodian" onClick={(e)=>{
                                    dispatch(routerRedux.push(`/goodsDetail/${v.dspecId}`))
                                }
                                }>立即购买</div>
                            </div>:<div style={{textAlign:"center"}}>
                                <Icon type={fenxiaoShare.id} style={{width:".7rem",height:'.7rem'}} onClick={()=>{
                                    dispatch(routerRedux.push(`/goodsDetail/${v.dspecId}`))
                                }}/>
                                    <div style={{color:"#ff0036",margin:".1rem 0"}}>赚{v.commission }元</div>
                                {my?"":v.isJoinMyStore==0?<div className="jiaruxiaodian" onClick={(e)=>{
                                    this.jiaru();
                                    return false;
                                }
                                }>加入小店</div>:<div className="yijiaruxiaodian">已加入  </div>}
                            </div>}

                        </Flex>

                    </Flex>
                </div>}

            </div>
        );
    }
}

export default DistributionItem;
